<!-- 岗位表单弹窗 -->
<form id="post-form" lay-filter="post-form" class="layui-form model-form">
    <input name="id" type="hidden"/>
    <div class="layui-form-item">
        <label class="layui-form-label">分 类</label>
        <div class="layui-input-block">
            <select name="classify" xm-select="postClassify" xm-select-radio xm-select-skin="normal" lay-verify="required">
                <option value="">请输入分类</option>
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">名 称</label>
        <div class="layui-input-block">
            <input name="name" placeholder="请输入名称" type="text" class="layui-input" maxlength="50"
                   lay-verify="required" required/>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">编 码</label>
        <div class="layui-input-block">
            <input name="code" placeholder="请输入编码" type="text" class="layui-input"/>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">备 注</label>
        <div class="layui-input-block">
            <textarea name="remark" placeholder="请输入备注" class="layui-textarea"></textarea>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">排序号</label>
        <div class="layui-input-block">
            <input name="sort" placeholder="请输入排序号" type="number" class="layui-input"/>
        </div>
    </div>
    <div class="layui-form-item model-form-footer">
        <button class="layui-btn layui-btn-primary close" ew-event="closeDialog" type="button">取消</button>
        <button class="layui-btn" lay-filter="post-form-submit" lay-submit>保存</button>
    </div>
</form>

<script>
    layui.use(['layer', 'crab', 'form', 'formSelects'], function () {
        var layer = layui.layer;
        var crab = layui.crab;
        var form = layui.form;
        var formSelects = layui.formSelects;
        var edit = false;

        form.render('radio');

        // 编辑的参数信息
        var post = crab.getFormData();
        if (post) {
            edit = true;
            // 回显参数数据
            form.val('post-form', post);
        }

        // 分类
        crab.get('/sys/dict/list_post-type', {}, function (data) {
            var l = data.length;
            if (l > 0) {
                var postData = new Array();
                for (var i = 0; i < data.length; i++) {
                    postData.push({name: data[i].name, value: data[i].content});
                }
                formSelects.data('postClassify', 'local', {arr: postData});
                if (post) {
                    formSelects.value('postClassify', [post.classify])
                }
            }
        });

        // 表单提交事件
        form.on('submit(post-form-submit)', function (data) {
            crab.request('/sys/post', data.field, function () {
                layer.msg(edit ? '修改成功' : '添加成功', {icon: 1});
                crab.finishPopupCenter();
            }, edit ? 'PUT' : 'POST');
            return false;
        });
    });
</script>